package com.zifeng.study.springbootshirojwtdemo.utils;

import com.zifeng.study.springbootshirojwtdemo.reponse.Response;

/**
 * @author: 吴梓锋
 * @date: 2021/01/27 23:06:14
 * @version: 1.0.0
 * @description: 接口返回工具类
 */
public class ResponseUtil {

    public static Response success(Object result) {
        Response response = new Response();
        response.setCode("200");
        response.setMsg("操作成功!");
        response.setResult(result);

        return response;
    }

    public static Response success(Object result, String msg) {
        Response response = new Response();
        response.setCode("200");
        response.setMsg(msg);
        response.setResult(result);

        return response;
    }

    public static Response success(String code, Object result, String msg) {
        Response response = new Response();
        response.setCode(code);
        response.setMsg(msg);
        response.setResult(result);

        return response;
    }

    public static Response error(Object result) {
        Response response = new Response();
        response.setCode("400");
        response.setMsg("操作失败!");
        response.setResult(result);
        return response;
    }

    public static Response error(Object result, String msg) {
        Response response = new Response();
        response.setCode("400");
        response.setMsg(msg);
        response.setResult(result);
        return response;
    }

    public static Response error(String code, Object result, String msg) {
        Response response = new Response();
        response.setCode(code);
        response.setMsg(msg);
        response.setResult(result);

        return response;
    }

    public static Response checkStatus(int flag) {
        return flag > 0 ? ResponseUtil.success(flag) : ResponseUtil.error(flag);
    }

    public static Response checkStatus(Object object) {
        return object == null ? ResponseUtil.error(null) : ResponseUtil.success(object);
    }

}
